package Java2Test.HashMap;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HashMapTest1 {
    public static void main(String[] args) {
        Student s1 = new Student("wangwu", 25);
        Student s2 = new Student("lisi", 24);
        Student s3 = new Student("zhangsan", 23);

        Map<Student, String> m = new HashMap<>();
        m.put(s1, "zhejiang");
        m.put(s2, "jiangsu");
        m.put(s3, "fujian");

        Set<Map.Entry<Student, String>> entries = m.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + " " + value);
        }

        Iterator<Map.Entry<Student, String>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<Student, String> next = iterator.next();
            Student key = next.getKey();
            String value = next.getValue();
            System.out.println(key + " " + value);
        }

        m.forEach((a, b) -> {
            System.out.println(a + " " + b);
        });


    }
}
